home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.09 Sep 87 / fortran source / misc stuff / prport folder / prport.asm < prev    next >
Encoding:
Assembly Source File  |  1986-01-20  |  8.5 KB  |  271 lines  |  [TEXT/EDIT]

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                    ;
  3. ;        FORTRAN 77 PRINT INTERFACE SUBROUTINE            ;
  4. ;                                    ;
  5. ;    PURPOSE:                            ;
  6. ;                                    ;
  7. ;        To interface to the print manager.            ;
  8. ;                                    ;
  9. ;    METHOD:                                ;
  10. ;                                    ;
  11. ;        Subroutine call from FORTRAN                ;
  12. ;                                    ;
  13. ;    ARGUMENTS:                            ;
  14. ;                                    ;
  15. ;        Name      Type        Description            ;
  16. ;                                    ;
  17. ;        FUNCTION  INTEGER*4    Bit mask specifying function    ;
  18. ;        ARGUMENTS INTEGER*4    Arguments to print manager.    ;
  19. ;                                    ;
  20. ;    CALLING SEQUENCE:                        ;
  21. ;                                    ;
  22. ;        CALL PRPORT(FUNCTION,ARGUMENTS)                ;
  23. ;                                    ;
  24. ; This subroutine is used with the file prport.inc, which includes      ;
  25. ; definitions of function codes for the functions and procedures     ;
  26. ; described in the Macintosh Print Manager manual.            ;
  27. ;                                    ;
  28. ; This file is provided for information only.  An assembled version is    ;
  29. ; available under PRPORT.SUB.                        ;
  30. ;                                    ;
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32. ;
  33. ;
  34. ; Edit history:
  35. ;
  36. ; 06 Nov 85    Started                            EWG
  37. ; 20 Jan 86    Sent to Compuserve.                    EWG
  38.  
  39.         INCLUDE QUICKEQU.D
  40.         INCLUDE QUICKTRAPS.D
  41.         INCLUDE SYSEQU.D
  42.         INCLUDE FSEQU.D
  43.         INCLUDE SYSERR.D
  44.         INCLUDE SYSTRAPS.D
  45.         INCLUDE TOOLEQU.D
  46.         INCLUDE TOOLEQUX.D
  47.         INCLUDE TOOLTRAPS.D
  48.         INCLUDE PREQU.D
  49.  
  50. PRPORT:    LEA    PRPORT(PC),A5        ; Get execution address.
  51.     CMPA.L    A0,A5            ; Are we loaded into the heap?
  52.     BMI.S    L1            ;   no
  53.     MOVE.W    #1,-8(A1)        ; Mark this subroutine as permanent.
  54. L1:    MOVE.L    A7,A4            ; Get pointer to return address.
  55.     MOVEM.L    A0/A6,-(A7)        ; Save system registers.
  56.     MOVE.L    -4(A0),A5        ; Restore Macintosh globals.
  57.     MOVE.L    D0,D7            ; Get number of arguments.
  58.     SUBQ.L    #1,D0            ; Subtract out control mask.
  59.     LSL.L    #2,D7            ; Get offset to begining of list.
  60.     ADD.L    D7,A4            ; Point to first argument.
  61.     MOVE.L    (A4),A3            ; Get pointer to control mask.
  62.     MOVE.L    (A3),D7            ; Get control mask.
  63.     TST.L    D7            ; Check for special function.
  64.     BMI    SPECIAL
  65.     
  66. ; Here to process a print manager request.  These are implemented as code
  67. ; contained in PDEF resources in the print resource file.
  68.     MOVEQ    #0,D3            ; Clear D3.
  69.     MOVE.B    D7,D3            ; Get offset to function.
  70.     ASR.L    #8,D7            ; Move function type into low byte.
  71.     MOVEQ    #0,D4            ; Clear D4.
  72.     MOVE.B    D7,D4            ; Get function type and unlock flag.
  73.     ASR.L    #8,D7            ; Move argument count into low byte.
  74.     MOVEQ    #0,D5            ; Clear D5.
  75.     MOVE.B    D7,D5            ; Get argument count.
  76.     ASR.L    #8,D7            ; Move PDEF resource number into low byte.
  77.     MOVEQ    #0,D6            ; Clear D6.
  78.     MOVE.B    D7,D6            ; Get resource number.
  79.  
  80. ; Get a copy of the argument count without the unlock flag in D7 and
  81. ; check for the correct number of arguments passed.
  82.     CMP.B    D5,D0            ; Correct argument count?
  83.     BEQ.S    OKARGS            ;   yes
  84.     MOVE.W    #dsSysErr,PrintErr    ; Return all-purpose error.
  85.     BRA    DONE            ; Bail out.
  86.     
  87. ; Get the correct PDEF resource.  It is assumed that the printer resource
  88. ; file and the print driver have already been opened by a called to PrOpen.
  89. ; Resource 0 means that the print method from low memory is used as the resource number.
  90. ; This controls draft vs. spool printing, which are separate resources.
  91. OKARGS:    TST.B    D6            ; Resource 0?
  92.     BNE.S    PR01            ;   no
  93.     MOVE.B    ChooserBits,D6        ; Get resource ID.
  94.     ANDI.B    #3,D6            ; Mask to bottom 2 bits.    
  95. PR01:    CLR.L    -(A7)            ; Room for a handle.
  96.     MOVE.L    #'PDEF',-(A7)
  97.     MOVE.W    D6,-(A7)
  98.     _GetResource
  99.     MOVE.L    (A7)+,D0        ; Was the resource found?
  100.     BNE.S    RESFND            ;   yes
  101.     MOVE.W    #resNotFound,PrintErr    ; Report error.
  102.     BRA    DONE            ; Bail out.    
  103. RESFND:    MOVE.L    D0,A2            ; Get handle to resource.
  104.     MOVE.L    A2,A0            ; Get a copy.
  105.     _HLock                ; Lock it.
  106.  
  107. ; Make room for the result of the requested function.
  108.     MOVE.B    D4,D7            ; Save the unlock flag.
  109.     BCLR    #7,D4            ; Strip unlock flag from return type.
  110.     TST.B    D4            ; Procedure?
  111.     BEQ.S    NORET            ;   yes
  112.     CMPI.B    #2,D4            ; Long result?
  113.     BEQ.S    CLLONG            ;   yes
  114.  
  115. ; Word or boolean.  Push a word.
  116.     CLR.W    -(A7)
  117.     BRA.S    NORET
  118.  
  119. CLLONG:    CLR.L    -(A7)
  120. NORET:
  121.  
  122. ; The arguments to the requested function are on the stack in FORTRAN format.
  123. ; The are all longwords passed by value.  The argument count is in D5.
  124. ; Push them on the stack for the print function.
  125. ; All of these functions have at least 1 argument.
  126. ARGLP:    MOVE.L    -(A4),A3        ; Get pointer to next argument.
  127.     MOVE.L    (A3),-(A7)        ; Push arguement.
  128.     SUBQ.B    #1,D5            ; One less.
  129.     BNE.S    ARGLP
  130.     
  131. ; Save the last argument.  If this is a procedure in resource 5 then this
  132. ; will be a print record, and we will put the bJDocLoop in global memory
  133. ; so that the printing routines will know which resource (0 or 1) to read
  134. ; in.
  135.     MOVE.L    (A7),D5
  136.  
  137. ; The code for the reqested function is in the PDEF resource read in above.
  138. ; Jump to it.
  139.     MOVE.L    (A2),A0            ; Dereference the handle.
  140.     ADDA.L    D3,A0            ; Add offset to routine vector.
  141.     JSR    (A0)            ; Call routine.
  142.     BTST    #7,D7            ; Unlock flag set?
  143.     BEQ.S    LOCKRES            ;   no - leave locked.
  144.     MOVE.L    A2,A0            ; Get a copy of the handle.
  145.     _HUNLOCK
  146. LOCKRES:
  147. ; If this was a print record setup function (in PDEF resource 4) then
  148. ; put the printing method into the low 2 bits of the chooser byte
  149. ; in low memory.  This will be used by the printing functions (in 
  150. ; PDEF resourec 0-3).
  151.     CMPI.B    #4,D6            ; Print record setup function?
  152.     BNE.S    FMTF77            ;  no
  153.     MOVE.B    ChooserBits,D6        ; Get the chooser field.
  154.     ANDI.B    #$FC,D6            ; Clear out bottom 2 bits.
  155.     MOVE.L    D5,A3            ; Get the print record handle (saved above)
  156.     MOVE.L    (A3),A3            ; Dereference it.
  157.     MOVE.B    prJob+bJDocLoop(A3),D5    ; Get print method.
  158.     ANDI.B    #3,D5            ; Clear to bottom 2 bits.
  159.     OR.B    D5,D6            ; Store in chooser field.
  160.     MOVE.B    D6,ChooserBits        ; Replace chooser field.
  161.  
  162. ; Convert the result to FORTRAN format.
  163. FMTF77:    TST.B    D4            ; Procedure?
  164.     BEQ.S    DONE            ;   yes
  165.     CMPI.B    #2,D4
  166.     BEQ.S    RTLONG            ; Return long word.
  167.     BMI.S    RTWORD            ; Return a word.
  168.  
  169. ; Here to return a boolean value.  Convert to FORTRAN logical (.TRUE. =
  170. ; all ones; .FALSE. = all zeros).
  171.     TST.W    (A7)+            ; Test result.
  172.     SNE    D0            ; Set low byte of D0 accordingly.
  173.     EXT.W    D0
  174.     EXT.L    D0            ; Return long result in D0.
  175.     BRA.S    DONE
  176.  
  177. RTLONG:    MOVE.L    (A7)+,D0
  178.     BRA.S    DONE
  179.  
  180. RTWORD:    MOVE.W    (A7)+,D0
  181.  
  182. DONE:    MOVEM.L    (A7)+,A0/A6        ; Restore system registers.
  183.     RTS
  184.  
  185. ; Process a special printer function.  These are functions which are not implemented
  186. ; as vectors into PDEF resources from the printer resource file.
  187. ; D7 contains the function number.
  188. SPECIAL:
  189.     EXT.L    D7            ; Clear upper word.
  190.  
  191. ; Tabled jump on function number.
  192.         ADD    D7,D7            ; Double type for a word offset.
  193.         MOVE.W    FUNCTAB(D7),D7        ; Get an offset to the code
  194.                                         ;   to process this case.
  195.         JSR    FUNCTAB(D7)        ; Jump to routine.
  196.     BRA.S    DONE
  197.     
  198. ; Function dispatch table.
  199. FUNCTAB:
  200.     DC.W    PROPEN - FUNCTAB
  201.     DC.W    PRCLOSE - FUNCTAB
  202.     DC.W    PRERROR - FUNCTAB
  203.     DC.W    PRSETERROR - FUNCTAB
  204.  
  205. ; Open the print resource file and the print driver.
  206. PROPEN:
  207. ; Get the name of the print resource file from the system resource file.
  208.     LINK    A6,#-ioQElSize        ; Get a parameter block.
  209.     MOVE.L    A7,A4            ; Point to the parameter block.
  210.     MOVE.L    A4,A0            ; Get a copy.
  211.     MOVEQ    #ioQElSize,D0        ; Get count to clear.
  212.     ASR.L    #1,D0            ; Divide by 2 for word count.
  213.     SUBQ.L    #1,D0            ; One less for DBF.
  214. CLPARM:    CLR.W    (A0)+            ; Clear a byte.
  215.     DBF    D0,CLPARM
  216.  
  217.     LEA    PRNAME,A0        ; Point to the print driver name.
  218.     MOVE.L    A0,ioFileName(A4)    ; Put file name in parameter block.
  219.     MOVE.L    A4,A0
  220.     _OPEN                ; Open the print driver.
  221.  
  222.     BSR    PRRESOPEN        ; Open the print resource file.
  223.  
  224. OPDONE:    UNLK    A6            ; Deallocate parameter block.
  225.     RTS
  226.  
  227. ; Open the print resource file.
  228. PRRESOPEN:
  229.     CLR.L    -(A7)            ; Room for handle result.
  230.     MOVE.L    #'STR ',-(A7)        ; STR resource type.
  231.     MOVE.W    #$E000,-(A7)        ; Resource number of print file name.
  232.     _GetResource            ; Get print file name from sys. res. file.
  233.     MOVE.L    (A7)+,D3        ; Get handle to string.
  234.     MOVE.L    D3,A0            ; Get a copy.
  235.     _HLock                ; Lock the string down.
  236.     CLR.W    -(A7)            ; Room for integer result.
  237.     MOVE.L    (A0),-(A7)        ; Get pointer to string.
  238.     _OpenResFile            ; Open the printer resource file.
  239.     MOVE.L    D3,A0            ; Get a copy of the string handle.
  240.     _HUnlock            ; Unlock it.
  241.     MOVE.W    (A7)+,D0        ; Get the reference number.
  242.     BMI.S    OPERR            ; Error.
  243.     RTS
  244. OPERR:    MOVE.W    ResErr,PrintErr        ; Set the printer error.
  245.     RTS
  246.  
  247. PRCLOSE:
  248.     BSR    PRRESOPEN            ; Make sure the file is open.
  249.     MOVE.W    D0,-(A7)        ; Push reference number.
  250.     _CloseResFile            ; Close it.
  251.     MOVE.W    ResErr,PrintErr    ; Set the printer error.
  252. CLDONE:    RTS
  253.  
  254. ; Return the printer error code from the system global.
  255. PRERROR:
  256.     MOVE.W    PrintErr,D0
  257.     EXT.L    D0
  258.     RTS
  259.  
  260. ; Set the printer error code in the system global.
  261. PRSETERROR:
  262.     MOVE.L    4(A7),A1        ; Get pointer to argument.
  263.     MOVE.L    (A1),D0            ; Get argument.
  264.     MOVE.W    D0,PrintErr
  265.     RTS
  266.     
  267. ; Name of print driver.
  268. PRNAME:    DC.B    6,'.PRINT',0
  269.  
  270.     END
  271.